package com.hanamaki.day1.day211025;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class demo {
    //注册驱动
    WebDriver driver;
    @BeforeMethod
    public void setUp(){
        /*注册本地火狐打开的位置*/
        System.setProperty("webdriver.gecko.driver","C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
        /*初始化*/
        driver = new FirefoxDriver();


    }
    @Test
    public void test() throws InterruptedException {
        driver.get("file:///C:/Users/Administrator/Desktop/testhtml/exam/testSelenium.html");
        WebElement element = driver.findElement(By.xpath("input[@value='Alert']"));
        element.click();
        /*如果 想要操作弹出对话框中的 按钮 必须 切换 渔村所在的 位置*/
        Alert alert = driver.switchTo().alert();
        /*强制等待*/
        Thread.sleep(3000);
        System.out.println(alert.getText());
        /*在一个alert中，即使没有取消按钮，也能取消。*/
        alert.accept();

    }
    @Test
    public void test2(){
        driver.get("file:///C:/Users/Administrator/Desktop/testhtml/exam/testSelenium.html");
        WebElement element = driver.findElement(By.xpath("input[2]"));
        element.click();
    }
    @Test
    public void test3(){
        driver.get("file:///C:/Users/Administrator/Desktop/testhtml/exam/testSelenium.html");
        WebElement element = driver.findElement(By.xpath("input[3]"));
        element.click();
    }
    @AfterMethod
    public void close(){
//        driver.close();
    }
}
